<template>
	<view>
		<u-sticky bgColor="#6492FF" offsetTop=0 customNavHeight=0>
			<navbox title="商务合作"></navbox>
		</u-sticky>
		<view class="con">
			<view class="con__top">
				易推帮只对接官方、官签服务商和独家渠道产品
			</view>
			<view class="con__box">

				<view class="con__box__item">
					<view class="con__box__item__label">
						项目名称
					</view>
					<input v-model="form.projectName" type="text" class="con__box__item__value" placeholder="请输入项目名称"
						placeholder-style="font-size:30rpx" />
				</view>
				<view class="con__box__item">
					<view class="con__box__item__label">
						项目单价
					</view>
					<input v-model='form.projectPrice' type="number" class="con__box__item__value"
						placeholder="请输入项目单价/元" placeholder-style="font-size:30rpx" />
				</view>
				<view class="con__box__item">
					<view class="con__box__item__label">
						需求数量
					</view>
					<input v-model="form.needCount" type="number" class="con__box__item__value" placeholder="请输入需求数量"
						placeholder-style="font-size:30rpx" />
				</view>
				<view class="con__box__item">
					<view class="con__box__item__label">
						联系人
					</view>
					<input v-model="form.linker" type="text" class="con__box__item__value" placeholder="请输入您的姓名"
						placeholder-style="font-size:30rpx" />
				</view>
				<view class="con__box__item">
					<view class="con__box__item__label">
						联系方式
					</view>
					<input v-model="form.tel" type="number" maxlength="11" class="con__box__item__value"
						placeholder="请输入您的手机号" placeholder-style="font-size:30rpx" />
				</view>
				<view class="con__box__item bb0">
					<view class="con__box__item__label">
						需求类型
					</view>
				</view>
				<view class="u-flex u-flex-y-center u-flex-wrap">
					<view class="con__box__check" v-for="(item,index) in lxlist" :class="index"
						@click="clickcheck(index)">
						<view class="con__box__check__box">
							<image v-if='!item.check' src="/static/img/my/nocheck.png"
								class="con__box__check__box__icon" mode=""></image>
							<image v-else src="/static/img/my/check.png" class="con__box__check__box__icon" mode="">
							</image>
						</view>
						{{item.dictLabel}}
					</view>
				</view>
				<view class="con__box__item bb0">
					<view class="con__box__item__label">
						项目身份
					</view>
				</view>
				<view class="u-flex u-flex-y-center u-flex-wrap">
					<view class="con__box__check" v-for="(item,index) in sflist" :class="index"
						@click="clickcheck1(index)">
						<view class="con__box__check__box">
							<image v-if='!item.check' src="/static/img/my/nocheck.png"
								class="con__box__check__box__icon" mode=""></image>
							<image v-else src="/static/img/my/check.png" class="con__box__check__box__icon" mode="">
							</image>
						</view>
						{{item.dictLabel}}
					</view>
				</view>
			</view>
			<view class="con__footer">
				<u-button :loading="loading" text="确认提交" @click="submit" color="#6492FF" shape='circle'></u-button>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		businessinit,
		businessadd
	} from '@/api/user.js'
	export default {
		data() {
			return {
				lxlist: [],
				sflist: [],
				form: {
					linker: '',
					needCount: '',
					needType: '',
					projectName: '',
					projectPrice: '',
					projectType: '',
					tel: ''
				},
				loading: false
			};
		},
		onLoad() {
			businessinit().then(res => {
				if (res.data.code == 200) {
					this.lxlist = res.data.data.need
					this.lxlist.map(t => {
						t.check = false
					})
					this.sflist = res.data.data.project
					this.sflist.map(t => {
						t.check = false
					})
				}
			})
		},
		methods: {
			clickcheck(index) {
				this.lxlist.map(t => {
					t.check = false
				})
				this.lxlist[index].check = true
				this.form.needType = this.lxlist[index].dictValue

				this.$forceUpdate()
			},
			clickcheck1(index) {
				this.sflist.map(t => {
					t.check = false
				})
				this.sflist[index].check = true
				this.form.projectType = this.sflist[index].dictValue
				this.$forceUpdate()
			},
			submit() {

				let {
					linker,
					projectName,
					projectPrice,
					needCount,
					tel,
					projectType,
					needType
				} = this.form
				if (!projectName) {
					this.$u.toast('请填写项目名称')
					return
				}
				if (!projectPrice) {
					this.$u.toast('请填写项目单价')
					return
				}
				if (!needCount) {
					this.$u.toast('请填写需求数量')
					return
				}
				if (!linker) {
					this.$u.toast('请填写联系人')
					return
				}
				if (tel.length!=11) {
					this.$u.toast('联系方式有误')
					return
				}
				if (!needType) {
					this.$u.toast('请选择需求类型')
					return
				}
				if (!projectType) {
					this.$u.toast('请项目身份')
					return
				}
				this.loading = true
				businessadd(this.form).then(res => {

					if (res.data.code == 200) {
						this.$u.toast('提交成功')
						setTimeout(() => {
							this.loading = false
							uni.navigateBack()
						}, 2000)
					} else {
						this.loading = false
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #f6f6f6;

	}

	.con {
		padding: 25rpx 16rpx;

		&__top {
			height: 87rpx;
			background: #FFFFFF;
			border-radius: 14rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			font-family: Source Han Sans SC;
			font-weight: 400;
			font-size: 30rpx;
			color: #3E3D3D;
			line-height: 30rpx;
		}

		&__box {
			margin-top: 25rpx;
			background: #FFFFFF;
			border-radius: 14rpx;
			padding: 30rpx 40rpx 20rpx;

			&__item {
				display: flex;
				align-items: center;
				justify-content: space-between;
				border-bottom: 1rpx solid rgba(205, 205, 205, .5);
				height: 70rpx;

				&__label {
					font-family: Source Han Sans SC;
					font-weight: 400;
					font-size: 30rpx;
					color: #3E3D3D;
					line-height: 30rpx;

				}

				&__value {
					width: 80%;
					font-family: Source Han Sans SC;
					font-weight: 400;
					font-size: 30rpx;
					color: #707070;
					text-align: right;
				}

				&__tx {
					width: 54.86rpx;
					height: 54.86rpx;
					border-radius: 50%;
				}
			}

			&__check {
				font-family: Source Han Sans SC;
				font-weight: 400;
				font-size: 30rpx;
				color: #707070;
				line-height: 30rpx;
				display: flex;
				align-items: center;
				width: 33.333%;
				margin-bottom: 36rpx;

				&__box {
					width: 30rpx;
					height: 30rpx;
					margin-right: 6rpx;

					&__icon {
						width: 30rpx;
						height: 30rpx;
					}
				}
			}
		}

		&__footer {
			padding: 25rpx 96rpx;

		}
	}

	.bb0 {
		border-bottom: 0;
	}

	.u-button {
		height: 60rpx;
	}
</style>